Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function wfprefs()
{
	this.prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("weather-forecaster.");
	this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
}

wfprefs.prototype = {
	classDescription: "user preferences for weather-forecaster",
	classID:          Components.ID("{7633c4c5-84b9-435e-a027-e14132fde922}"),
	contractID:       "@weather-forecaster/wfprefs;1",
	QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIwfprefs]),

	getAPI: function()
	{
		return this.prefs.getCharPref("api");
	},

	isWindMPH: function() 
	{
		if (this.prefs.getCharPref("wind") == "mph")
			return true;
		return false;
	},
	
	isTempF: function()
	{
		if (this.prefs.getCharPref("temperature") == "f")
			return true;
		return false;	
	},

	getZip: function()
	{
		return this.prefs.getCharPref("zip");	
	},

	isHumidity: function()
	{
		if (this.prefs.getCharPref("humidity") == "off")
			return false;
		return true;	
	},

	setAPI: function(api)
	{
		this.prefs.setCharPref("api",api);	
	},

	setWindMPH: function()
	{
		this.prefs.setCharPref("wind","mph");	
	},

	setWindKPH: function()
	{
		this.prefs.setCharPref("wind","kph");
	},

	setTempF: function()
	{
		this.prefs.setCharPref("temperature","f");
	},

	setTempC: function()
	{
		this.prefs.setCharPref("temperature","c");
	},

	setZip: function(zip)
	{
		this.prefs.setCharPref("zip",zip);
	},

	onHumidity: function()
	{
		this.prefs.setCharPref("humidity","on");	
	},

	offHumidity: function()
	{
		this.prefs.setCharPref("humidity","off");	
	}
};

var components = [wfprefs];
if ("generateNSGetFactory" in XPCOMUtils)
  var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);  // Firefox 4.0 and higher
else
  var NSGetModule = XPCOMUtils.generateNSGetModule(components);    // Firefox 3.x
